<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="__LAYUI__/layui.js"></script>
    <link href="__LAYUI__/css/layui.css" rel="stylesheet" />
</head>
<body>
<table id="table" lay-filter="mono"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-mini" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-warm layui-btn-mini" lay-event="txt">txt文件</a>
    <a class="layui-btn layui-btn-danger layui-btn-mini" lay-event="del">删除</a>
</script>

<script>
    layui.use(['table','layer','jquery'],function () {
        var table = layui.table
            ,layer = layui.layer
            ,$ = layui.$;
        if({$level}=='0'){
            table.render({
                elem:'table',
                height:370,
                page:true,
                limit:10,
                skin: 'line',
                cols:[[
                    {field:'Id',title:'ID',width:100},
                    {field:'book_name',title:'著作名称',width:200},
                    {field:'book_author',title:'著作人',width:200},
                    {field:'status',title:'书号状态',width:200},
                    {fixed: 'right', width: 200, align: 'center', toolbar: '#barDemo'}
                ]],
                url:'/index/monograph/getMonographInfo',
                response:{
                    statusName:'code',
                    statusCode:1
                }
                ,id:'materTable'

            });

            table.on('tool(mono)', function(obj) {
                var data = obj.data;
                console.log(data.Id)
                if (obj.event === 'del') {
                    layer.open({
                        type:0 ,
                        content:'确定删除?',
                        yes:function (index, layero) {
                            $.ajax({
                                type:'post',
                                url:'/index/monograph/delMonograph',
                                data:{
                                    'id':data.Id
                                },
                                success:function (result) {
                                    if(result.code){
                                        layer.msg(result.msg, {
                                            icon: 1,
                                            time: 3000 //2秒关闭（如果不配置，默认是3秒）
                                        });
                                    }
                                    table.reload('materTable',{
                                    });
                                }
                            });

                            layer.close(index);
                        }

                    });
                }

                if(obj.event === 'edit'){
                    layer.open({
                        type: 2,
                        offset:'0px',
                        title: '专著修改' ,
                        scrollbar: false,
                        resize: false,
                        area:['600px','650px'],
                        shadeClose: true,
                        content: ['/index/Monograph/changeMonograph?id='+data.Id,'no'],
                    });
                }

                if (obj.event === 'txt') {
                    window.location.href='/index/File/backUpMono?id='+data.Id;
                }

            });




        }else{
            table.render({
                elem:'table',
                height:370,
                page:true,
                limit:10,
                cols:[[
                    {field:'Id',title:'ID',width:100},
                    {field:'book_name',title:'著作名称',width:200},
                    {field:'book_author',title:'著作人',width:200},
                    {field:'status',title:'书号状态',width:200},
                ]],
                url:'/index/monograph/getMonographInfo',
                response:{
                    statusName:'code',
                    statusCode:1
                }

            });
        }

    })
</script>
</body>
</html>